package com.dreamer.service.lottery;

import com.dreamer.domain.lottery.Prize;
import com.dreamer.repository.lottery.PrizeDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ps.mx.otter.utils.SearchParameter;

import java.util.List;

@Service
public class PrizeHandler {

    @Autowired
    private PrizeDAO prizeDAO;

    @Transactional
    public Prize saveOrUpdate(Prize prize){
        Prize instance = prizeDAO.merge(prize);
        LOG.debug("新增奖品成功"+instance);
        return prize;
    }

    @Transactional
    public void removeActivity(Prize prize) {
        prizeDAO.delete(prize);
        LOG.debug("删除奖品成功");
    }

    private final Logger LOG = LoggerFactory.getLogger(getClass());

    public Prize findById(Integer integer) {
        return  prizeDAO.findById(integer);
    }

    public List<Prize> searchAllByPage(SearchParameter<Prize> parameter) {
        return prizeDAO.searchAllByPage(parameter);
    }

    public List<Prize> findByCode(String code){
        return prizeDAO.findByCode(code);
    }

    public List<Prize> findByLotteryCode(String code){
        List<Prize> list = prizeDAO.findByLotteryCode(code);
        return list;
    }

    public List<Prize> findAll(){
        return prizeDAO.findAll();
    }

}
